﻿using UnityEditor;
using UnityEngine;
using System.Collections;
using Babybus.Framework.ExtensionMethods;

public class DecryptEditor : EditorWindow {


    [MenuItem("Utility/DecryptFile")]
    static void AddWindow()
    {
        DecryptEditor window = EditorWindow.GetWindow<DecryptEditor>(true, "解密Asset Store 下载的资源");
        window.Show();
    }

    private string m_InputFilePath;
    private string m_InputFileKey;

    void OnGUI()
    {
        m_InputFilePath = EditorGUILayout.TextField("文件Path：",m_InputFilePath);
        m_InputFileKey  = EditorGUILayout.TextField("文件 Key：",m_InputFileKey);

        if(GUILayout.Button("解密", GUILayout.Width(200)))
        {
            DecryptFile();
        }
    }


     void DecryptFile()
    {
        var inputFile = m_InputFilePath;
        var key = m_InputFileKey;

        var unityEditor = typeof(Editor).Assembly;

        var assetStoreUtils = unityEditor.GetType("UnityEditor.AssetStoreUtils");
        assetStoreUtils.Invoke("DecryptFile", inputFile, inputFile + ".unitypackage", key);
    }

}
